using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
//using DevExpress.XtraReports.UI;
using NetROS.Tiers.Entities;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;

namespace NetRosApp.Klijenti.Reports
{
    public partial class PonudaPredracun : DevExpress.XtraReports.UI.XtraReport,IParametriIzvjestaja
    {
        public PonudaPredracun()
        {
            InitializeComponent();
        }


        public PonudaPredracun(Dokument dokument)
        {
            InitializeComponent();
            bindingSource1.DataSource = dokument;
            //xrDatumMjesto.Text = string.Format("[IDOrganizacijaOdSource.IDMjestoSource.Naziv], {0}", DateTime.Now.ToShortDateString());
            xrDatumMjesto.Text = "[IDOrganizacijaOdSource.IDMjestoSource.Naziv], [Datum!dd.MM.yyyy]";
            //System.Drawing.Imaging.Metafile tmp = new System.Drawing.Imaging.Metafile(@"H:\NetROS\NetRosApp\Slike\Reporti\zaglavlje.wmf");
           // System.Drawing.Imaging.Metafile tmp = new System.Drawing.Imaging.Metafile(Application.StartupPath + "\\zaglavlje.wmf");
           // int visina = tmp.Size.Height;
           // int duzina = tmp.Size.Width;
           // if (visina != 0)
           // {
           //     xrPictureBox1.Height = (int)(((decimal)tmp.Height / (decimal)tmp.Width) * (decimal)625);
           // }

           //xrPictureBox1.Image = tmp;
           

        }

        #region IParametriIzvjestaja Members

        public void SetParametri()
        {
            xrLParametar1.Text = (bindingSource1.DataSource as Dokument).IDDokumentTipSource.PrilagodenDokumentTip.Parametar1;
            String Otpremnice = String.Empty;
            foreach (Veza tmp in (bindingSource1.DataSource as Dokument).VezaCollectionGetByIDParent)
            {
                if (tmp.IDChildSource.IDDokumentTip == (int)DokumentTipList.Otpremnica)
                {
                    xrLabel24.Visible = false;
                    xrLabel27.Visible = false;
                    xrlIzdatnice.Visible = true;
                    xrLOtprem.Visible = true;
                    Otpremnice += tmp.IDChildSource.Oznaka + " ";
                }
            }
            xrlIzdatnice.Text = Otpremnice;
            Dokument dokument = (bindingSource1.DataSource as Dokument);
            if (dokument != null && dokument.IDOrganizacijaOdSource != null && !String.IsNullOrEmpty(dokument.IDOrganizacijaOdSource.Adresa)
              && !String.IsNullOrEmpty(dokument.IDOrganizacijaOdSource.Telefon)
              && dokument.IDOrganizacijaOdSource.IDMjestoSource != null)
            {
                xrPanel1.Visible = true;
            }
            else
            {
                xrPanel1.Visible = false;
            }
        }

        #endregion

        private void xrLabel16_SummaryCalculated(object sender, TextFormatEventArgs e)
        {
            if (e.Value != null)
            {
                xrLabel16.Summary.FormatString="{0:n2}";
            }
            

        }

        private void xrLabel33_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            try
            {

                //xrLabel33.Text = (bindingSource1.DataSource as Dokument).Oznaka.ToString() + "-" + (bindingSource1.DataSource as Dokument).IDKlijentSource.MB.ToString();
                xrLabel33.Text = PostavkeReporta.GetPozivNaBr(bindingSource1.DataSource as Dokument);
            }
            catch
            {
            }
            //DevExpress.XtraReports.UI.XRLabel _local = sender as DevExpress.XtraReports.UI.XRLabel;

            //          DevExpress.XtraReports.UI.XRLabel _local = sender as DevExpress.XtraReports.UI.XRLabel;
            //_local.Summary
                    //  _local.Text =((Decimal)(Convert.ToDecimal(xrLabel15.Text) * Convert.ToDecimal(xrLabel2.Text))).ToString("n2");
        //    _local.Text = ((Decimal)((Convert.ToDecimal(xrLabel18.Summary.GetResult()) + Convert.ToDecimal(xrLabe19.Summary.GetResult())) - Convert.ToDecimal(xrLabel7.Summary.GetResult()))).ToString("n3"); ;





        //    DevExpress.XtraReports.UI.XRLabel _local = sender as DevExpress.XtraReports.UI.XRLabel;


        //    _local.Text = ((Decimal)((Convert.ToDecimal(xrLabel2.Summary.GetResult()) + Convert.ToDecimal(xrLabel7.Summary.GetResult())) - Convert.ToDecimal(xrLabel8.Summary.GetResult()))).ToString("n3");
            
        }

        private void xrLabel32_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            try
            {
                String _loc = (GetCurrentColumnValue("IDValuteSource") as Valuta).Kratica;
                String _loc2 = Convert.ToDecimal(xrLabel32.Summary.GetResult()).ToString("n2");

                xrLabel32.Summary.FormatString = String.Format("ZA PLATITI:  {0} {1}", _loc2, _loc);
            }
            catch
            { }
        }

        private void xrLabel58_PrintOnPage(object sender, PrintOnPageEventArgs e)
        {
            if (e.PageIndex != 0)
            {
                (sender as XRLabel).Visible = true;
            }
            else
            {
                (sender as XRLabel).Visible = false;
            }
        }


    }
}
